package com.ruoyi.sourceplan.masterdata.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.sourceplan.masterdata.domain.MdSupplier;
import com.ruoyi.sourceplan.masterdata.mapper.MdSupplierMapper;
import com.ruoyi.sourceplan.masterdata.service.IMdSupplierService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;
import java.util.List;
import java.util.Map;

/**
 * 供应商Service业务层处理
 *
 * @author husky
 * @date 2023-11-04
 */
@Service
public class MdSupplierServiceImpl extends ServiceImpl<MdSupplierMapper, MdSupplier> implements IMdSupplierService {

    @Autowired
    private MdSupplierMapper mdSupplierMapper;

    /**
     * 查询供应商列表
     *
     * @param mdSupplier 供应商
     * @return 供应商
     */
    @Override
    public List<MdSupplier> selectMdSupplierList(MdSupplier mdSupplier)
    {
        List<MdSupplier> mdSupplierList = mdSupplierMapper.selectList(buildQueryWrapper(mdSupplier));
        return mdSupplierList;
    }


    private LambdaQueryWrapper<MdSupplier> buildQueryWrapper(MdSupplier query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<MdSupplier> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(query.getNumber()), MdSupplier::getNumber, query.getNumber());
        lqw.like(StringUtils.isNotBlank(query.getName()), MdSupplier::getName, query.getName());
        lqw.eq(StringUtils.isNotBlank(query.getStatus()), MdSupplier::getStatus, query.getStatus());
        lqw.orderByDesc(MdSupplier::getCreateTime);
        return lqw;
    }

}
